|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
SessionBeanWriter.java | 0% | 5.6% | 33.3% | 5.8% |
|
1 |
/*
|
|
2 |
* Copyright 2001-2004 The Apache Software Foundation.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
|
16 |
|
|
17 |
package org.apache.geronimo.ews.ws4j2ee.toWs.ejb;
|
|
18 |
|
|
19 |
import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
|
|
20 |
import org.apache.geronimo.ews.ws4j2ee.context.SEIOperation;
|
|
21 |
import org.apache.geronimo.ews.ws4j2ee.context.j2eeDD.EJBContext;
|
|
22 |
import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
|
|
23 |
import org.apache.geronimo.ews.ws4j2ee.toWs.JavaClassWriter;
|
|
24 |
|
|
25 |
import java.util.ArrayList;
|
|
26 |
import java.util.Iterator;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* <p>This class can be used to write the appropriate SessionBean
|
|
30 |
* class for the given port type.
|
|
31 |
* A Stateless Session Bean, as defined by the Enterprise JavaBeans specification,
|
|
32 |
* can be used to implement a Web service to be deployed in the EJB container.
|
|
33 |
* A Stateless Session Bean does not have to worry about multi-threaded access.
|
|
34 |
* The EJB container is required to serialize request flow through any particular
|
|
35 |
* instance of a Service Implementation Bean. The requirements for creating a Service
|
|
36 |
* Implementation Bean as a Stateless Session EJB are repeated in part here.</p>
|
|
37 |
* <ol>
|
|
38 |
* <li>The Service Implementation Bean must have a default public constructor.</li>
|
|
39 |
* <li>The Service Implementation Bean may implement the Service Endpoint Interface,
|
|
40 |
* but it is not required to do so. The bean must implement all the method
|
|
41 |
* signatures of the SEI.<li>
|
|
42 |
* <li>The Service Implementation Bean methods are not required to throw
|
|
43 |
* javax.rmi.RemoteException. The business methods of the bean must be public
|
|
44 |
* and must not be final or static. It may implement other methods in addition
|
|
45 |
* to those defined by the SEI.</li>
|
|
46 |
* <li>A Service Implementation Bean must be a stateless object.
|
|
47 |
* A Service Implementation Bean must not save client specific state
|
|
48 |
* across method calls either within the bean instance�s data members or
|
|
49 |
* external to the instance.</li>
|
|
50 |
* <li>The class must be public, must not be final and must not be abstract.</li>
|
|
51 |
* <li>The class must not define the finalize() method.</li>
|
|
52 |
* <li>Currently, it must implement the ejbCreate() and ejbRemove() methods which
|
|
53 |
* take no arguments. This is a requirement of the EJB container, but generally
|
|
54 |
* can be stubbed out with an empty implementation.</li>
|
|
55 |
* <li>Currently, a Stateless Session Bean must implement the javax.ejb.SessionBean
|
|
56 |
* interface either directly or indirectly. This interface allows the container to notify the Service Implementation Bean of impending changes in its state. The full requirements of this interface are defined in the Enterprise JavaBeans specification section 7.5.1.</li>
|
|
57 |
* <li>The Enterprise JavaBeans specification section 7.8.2 defines the allowed
|
|
58 |
* container service access requirements.</li>
|
|
59 |
* </ol>
|
|
60 |
* <h5>Exposing an existing EJB</h5>
|
|
61 |
* <p>An existing Enterprise JavaBean may be used as a Service Implementation Bean if it meets the following requirements:</p>
|
|
62 |
* <ol>
|
|
63 |
* <li>The business methods of the EJB bean class that are exposed on the SEI must meet the Service</li>
|
|
64 |
* <li>Implementation Bean requirements defined in section 5.3.1.</li>
|
|
65 |
* <li>The SEI must meet the requirements described in the JAX-RPC specification for Service Endpoint Interfaces.</li>
|
|
66 |
* <li>The transaction attributes of the SEI methods must not include Mandatory.</li>
|
|
67 |
* <li>The developer must package the Web service as described in section 5.4 and must specify an ejb-link from the port in the Web services deployment descriptor to the existing EJB.</li>
|
|
68 |
* <ol>
|
|
69 |
*
|
|
70 |
* @author Rajith Priyanga
|
|
71 |
* @author Srinath Perera
|
|
72 |
* @date Nov 26, 2003
|
|
73 |
*/
|
|
74 |
public class SessionBeanWriter extends JavaClassWriter { |
|
75 |
private String name;
|
|
76 |
protected EJBContext ejbcontext;
|
|
77 |
|
|
78 |
/**
|
|
79 |
* Constructs a SessionBeanWriter.
|
|
80 |
*
|
|
81 |
* @param portType The port type which contains the details.
|
|
82 |
* @throws GenerationFault
|
|
83 |
*/
|
|
84 | 2 |
public SessionBeanWriter(J2EEWebServiceContext context, EJBContext ejbcontext) throws GenerationFault { |
85 | 2 |
super(context, ejbcontext.getImplBean());
|
86 | 2 |
this.ejbcontext = ejbcontext;
|
87 |
} |
|
88 |
|
|
89 | 0 |
protected void writeAttributes() throws GenerationFault { |
90 |
} |
|
91 |
|
|
92 | 0 |
protected void writeConstructors() throws GenerationFault { |
93 |
} |
|
94 |
|
|
95 | 0 |
protected void writeMethods() throws GenerationFault { |
96 | 0 |
String parmlistStr = "";
|
97 | 0 |
ArrayList operations = j2eewscontext.getMiscInfo().getSEIOperations(); |
98 | 0 |
for (int i = 0; i < operations.size(); i++) { |
99 | 0 |
SEIOperation op = (SEIOperation) operations.get(i); |
100 | 0 |
String returnType = op.getReturnType(); |
101 | 0 |
returnType = (returnType == null) ? "void" : returnType; |
102 | 0 |
out.write("\tpublic " + returnType + " " + op.getMethodName() + "("); |
103 | 0 |
Iterator pas = op.getParameterNames().iterator(); |
104 | 0 |
boolean first = true; |
105 | 0 |
while (pas.hasNext()) {
|
106 | 0 |
String name = (String) pas.next(); |
107 | 0 |
String type = (String) op.getParameterType(name); |
108 | 0 |
if (first) {
|
109 | 0 |
first = false;
|
110 | 0 |
out.write(type + " " + name);
|
111 | 0 |
parmlistStr = parmlistStr + name; |
112 |
} else {
|
|
113 | 0 |
out.write("," + type + " " + name); |
114 | 0 |
parmlistStr = "," + name;
|
115 |
} |
|
116 |
} |
|
117 | 0 |
out.write(")");
|
118 |
// out.write(") throws java.rmi.RemoteException");
|
|
119 |
// ejb giving problems deploying check this
|
|
120 |
// ArrayList faults = op.getFaults();
|
|
121 |
// for (int j = 0; j < faults.size(); j++) {
|
|
122 |
// out.write("," + (String) faults.get(i));
|
|
123 |
// }
|
|
124 | 0 |
out.write("{\n");
|
125 | 0 |
if ("int".equals(returnType)) { |
126 | 0 |
out.write("\t\t\treturn 12;\n");
|
127 | 0 |
} else if ("float".equals(returnType)) { |
128 | 0 |
out.write("\t\t\treturn 0.0f;\n");
|
129 | 0 |
} else if ("double".equals(returnType)) { |
130 | 0 |
out.write("\t\t\treturn 0.0d;\n");
|
131 | 0 |
} else if ("short".equals(returnType)) { |
132 | 0 |
out.write("\t\t\treturn (short)0.0;\n");
|
133 | 0 |
} else if ("boolean".equals(returnType)) { |
134 | 0 |
out.write("\t\t\treturn false;\n");
|
135 | 0 |
} else if ("byte".equals(returnType)) { |
136 | 0 |
out.write("\t\t\treturn (byte)24;\n");
|
137 | 0 |
} else if ("long".equals(returnType)) { |
138 | 0 |
out.write("\t\t\treturn (long)0.0l;\n");
|
139 | 0 |
} else if ("char".equals(returnType)) { |
140 | 0 |
out.write("\t\t\treturn 'w';\n");
|
141 | 0 |
} else if ("void".equals(returnType)) { |
142 |
} else {
|
|
143 | 0 |
out.write("\t\t\treturn null;\n");
|
144 |
} |
|
145 | 0 |
out.write("\t}\n");
|
146 |
} |
|
147 | 0 |
out.write("\tpublic javax.naming.Context getInitialContext()throws javax.naming.NamingException{\n");
|
148 | 0 |
out.write("\t java.util.Properties env = new java.util.Properties();\n");
|
149 | 0 |
out.write("\t env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,\"org.jnp.interfaces.NamingContextFactory\");\n");
|
150 | 0 |
out.write("\t env.put(javax.naming.Context.PROVIDER_URL, \"127.0.0.1:1099\");\n");
|
151 | 0 |
out.write("\t return new javax.naming.InitialContext(env);\n");
|
152 | 0 |
out.write("\t}\n");
|
153 | 0 |
out.write("\tpublic void ejbCreate() {}\n");
|
154 | 0 |
out.write("\tpublic void ejbActivate() throws javax.ejb.EJBException, java.rmi.RemoteException {}\n");
|
155 | 0 |
out.write("\tpublic void ejbPassivate() throws javax.ejb.EJBException, java.rmi.RemoteException {}\n");
|
156 | 0 |
out.write("\tpublic void ejbRemove() throws javax.ejb.EJBException, java.rmi.RemoteException {}\n");
|
157 | 0 |
out.write("\tpublic void setSessionContext(javax.ejb.SessionContext arg0)throws javax.ejb.EJBException, java.rmi.RemoteException {}\n");
|
158 |
} |
|
159 |
|
|
160 |
/* (non-Javadoc)
|
|
161 |
* @see org.apache.geronimo.ews.ws4j2ee.toWs.JavaClassWriter#getimplementsPart()
|
|
162 |
*/
|
|
163 | 0 |
protected String getimplementsPart() {
|
164 | 0 |
return " implements javax.ejb.SessionBean"; |
165 |
} |
|
166 |
|
|
167 |
/* (non-Javadoc)
|
|
168 |
* @see org.apache.geronimo.ews.ws4j2ee.toWs.AbstractWriter#isOverWrite()
|
|
169 |
*/
|
|
170 | 2 |
protected boolean isOverWrite() { |
171 | 2 |
return false; |
172 |
} |
|
173 |
|
|
174 |
} |
|
175 |
|
|